import Vue from 'vue'
import Router from 'vue-router'
// import login from '@/components/login/login.vue'
import tabbar from '@/components/tabbar/tabbar.vue'
Vue.use(Router)
const router = new Router({
  linkActiveClass: 'active',
  routes: [{
    path: '/',
    component: tabbar,
    redirect: '/oauth'
  }, {
    path: '/tabbar',
    component: tabbar,
    redirect: '/Hello',
    children: [{
      path: '/Hello',
      component: resolve => {
        require(['@/components/Hello/Hello.vue'], resolve)
      }
    }, {
      path: '/notice',
      component: resolve => {
        require(['@/components/notice/notice.vue'], resolve)
      }
    }, {
      path: '/pointto',
      component: resolve => {
        require(['@/components/pointto/pointto.vue'], resolve)
      }
    }, {
      path: '/mine',
      component: resolve => {
        require(['@/components/mine/mine.vue'], resolve)
      }
    }]
  },  {
    path: '/site',
      component: resolve => {
      require(['@/components/Index/Index.vue'], resolve)
    }
  }, {
    path: '/oauth',
      component: resolve => {
      require(['@/components/oauth/oauth.vue'], resolve)
    }
  },{
    path: '/noticeDetails',
    component: resolve => {
      require(['@/components/noticeDetails/noticeDetails.vue'], resolve)
    }
  },{
    path: '/pointtoList',
    component: resolve => {
      require(['@/components/pointtoList/pointtoList.vue'], resolve)
    }
  }, {
    path: '/personalInformation',
    component: resolve => {
      require(['@/components/personalInformation/personalInformation.vue'], resolve)
    }
  }, {
    path: '/modifyInformation',
    component: resolve => {
      require(['@/components/modifyInformation/modifyInformation.vue'], resolve)
    }
  }, {
    path: '/myClass',
    component: resolve => {
      require(['@/components/myClass/myClass.vue'], resolve)
    }
  }, {
    path: '/courseDetails',
    component: resolve => {
      require(['@/components/courseDetails/courseDetails.vue'], resolve)
    }
  }, {
    path: '/personalInformation',
    component: resolve => {
      require(['@/components/personalInformation/personalInformation.vue'], resolve)
    }
  }, {
  path: '/query',
    component: resolve => {
    require(['@/components/query/query.vue'], resolve)
  }
  },{
  path: '/queryResult',
    component: resolve => {
    require(['@/components/queryResult/queryResult.vue'], resolve)
  }
},{
    path: '/regist',
    component: resolve => {
      require(['@/components/regist/regist.vue'], resolve)
    }
  }, {
    path: '/agreement',
    component: resolve => {
      require(['@/components/agreement/agreement.vue'], resolve)
    }
  }, {
    path: '/login',
    component: resolve => {
      require(['@/components/login/login.vue'], resolve)
    }
  }, {
    path: '/payment',
    component: resolve => {
      require(['@/components/payment/payment.vue'], resolve)
    }
  }],
  base: '/wx/'
})
router.beforeEach((to, from, next) => {
  let studentId = window.sessionStorage.getItem('studentId')
  if (to.path === '/login') {
    if (studentId !== null && studentId !== '-1') {
      console.log(123454)
      next({
        path: '/tabbar'
      })
    } else {
      next()
    }
  } /*else if (from.path === '/login') {
    if ((studentId == null || studentId == '-1') && to.path !== '/regist') {
      next({
        path: '/login'
      })
    } else {
      next()
    }
  }*/ else {
    next()
  }
})
// router.beforeEach((to, from, next) => {
//   if (to.path === '/mine') {
//     console.log('to', to)
//     if (window.sessionStorage.getItem('studentId') === '-1') {
//       next({
//         path: '/login'
//       })
//     } else {
//       next()
//     }
//   } else {
//     next()
//   }
// })
export default router
